/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package presentacion;

import javax.swing.RowSorter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;
import negocio.nModeloProgramado;

/**
 *
 * @author eduardo
 */
public class pModeloABC extends javax.swing.JFrame {

    
     DefaultTableModel dtm;
    
    
    /**
     * Creates new form pModeloABC
     */
    public pModeloABC() {
        initComponents();
        
        this.setLocationRelativeTo(null);
        
        dtm = (DefaultTableModel) this.datosTable.getModel();
        
       
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        atrasButton = new javax.swing.JButton();
        jSeparator1 = new javax.swing.JToolBar.Separator();
        eliminarButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JToolBar.Separator();
        agregarButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JToolBar.Separator();
        resultadoButton = new javax.swing.JButton();
        jSeparator4 = new javax.swing.JToolBar.Separator();
        jButton1 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        datosTable = new javax.swing.JTable();
        costoUnitarioTextField = new javax.swing.JTextField();
        articuloTextField = new javax.swing.JTextField();
        indiceTextField = new javax.swing.JTextField();
        demandaUnidadTextField = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        tipoDemandaComboBox = new javax.swing.JComboBox();
        jPanel2 = new javax.swing.JPanel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jPanel1.setBackground(java.awt.SystemColor.activeCaption);

        jToolBar1.setRollover(true);

        atrasButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        atrasButton.setText("Atras");
        atrasButton.setFocusable(false);
        atrasButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        atrasButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        atrasButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                atrasButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(atrasButton);
        jToolBar1.add(jSeparator1);

        eliminarButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        eliminarButton.setText("Eliminar");
        eliminarButton.setFocusable(false);
        eliminarButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        eliminarButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        eliminarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                eliminarButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(eliminarButton);
        jToolBar1.add(jSeparator2);

        agregarButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        agregarButton.setText("Agregar");
        agregarButton.setFocusable(false);
        agregarButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        agregarButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        agregarButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                agregarButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(agregarButton);
        jToolBar1.add(jSeparator3);

        resultadoButton.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        resultadoButton.setText("Resultado");
        resultadoButton.setFocusable(false);
        resultadoButton.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        resultadoButton.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        resultadoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                resultadoButtonActionPerformed(evt);
            }
        });
        jToolBar1.add(resultadoButton);
        jToolBar1.add(jSeparator4);

        jButton1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jButton1.setText("Limpiar todo");
        jButton1.setFocusable(false);
        jButton1.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jButton1.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jToolBar1.add(jButton1);

        jLabel6.setFont(new java.awt.Font("DejaVu Sans", 1, 24)); // NOI18N
        jLabel6.setText("MODELO ABC");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(341, 341, 341)
                .addComponent(jLabel6)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 22, Short.MAX_VALUE)
                .addComponent(jLabel6)
                .addGap(18, 18, 18)
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        datosTable.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        datosTable.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Indice de Criticidad", "Articulo", "Costo Unitario", "Demanda Unidad", "Demanda Anual Dolares", "%", "Acumulado", "ABC", "αβγ "
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        datosTable.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(datosTable);
        if (datosTable.getColumnModel().getColumnCount() > 0) {
            datosTable.getColumnModel().getColumn(0).setResizable(false);
            datosTable.getColumnModel().getColumn(0).setPreferredWidth(125);
            datosTable.getColumnModel().getColumn(1).setResizable(false);
            datosTable.getColumnModel().getColumn(2).setResizable(false);
            datosTable.getColumnModel().getColumn(2).setPreferredWidth(100);
            datosTable.getColumnModel().getColumn(3).setResizable(false);
            datosTable.getColumnModel().getColumn(3).setPreferredWidth(100);
            datosTable.getColumnModel().getColumn(4).setResizable(false);
            datosTable.getColumnModel().getColumn(4).setPreferredWidth(150);
            datosTable.getColumnModel().getColumn(5).setResizable(false);
            datosTable.getColumnModel().getColumn(5).setPreferredWidth(50);
            datosTable.getColumnModel().getColumn(6).setResizable(false);
            datosTable.getColumnModel().getColumn(7).setResizable(false);
            datosTable.getColumnModel().getColumn(7).setPreferredWidth(30);
            datosTable.getColumnModel().getColumn(8).setResizable(false);
            datosTable.getColumnModel().getColumn(8).setPreferredWidth(30);
        }

        costoUnitarioTextField.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        articuloTextField.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        indiceTextField.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        demandaUnidadTextField.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel1.setText("Indice:");

        jLabel2.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel2.setText("Articulo:");

        jLabel3.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel3.setText("Costo Unitario:");

        jLabel4.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel4.setText("Demanda Unidad:");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        jLabel5.setText("Tipo de demanda:");

        tipoDemandaComboBox.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        tipoDemandaComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Mensual", "Anual" }));

        jPanel2.setBackground(java.awt.SystemColor.activeCaption);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 26, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jLabel2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(articuloTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(indiceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(46, 46, 46)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel4)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(demandaUnidadTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jLabel3)
                                .addGap(18, 18, 18)
                                .addComponent(costoUnitarioTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(37, 37, 37)
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(tipoDemandaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 115, Short.MAX_VALUE)))
                .addContainerGap())
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(28, 28, 28)
                        .addComponent(jLabel3))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(indiceTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(costoUnitarioTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1)))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(articuloTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(demandaUnidadTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)
                        .addComponent(jLabel5)
                        .addComponent(tipoDemandaComboBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(31, 31, 31)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void atrasButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_atrasButtonActionPerformed
        
        pModeloProgramado pm = new pModeloProgramado();
        
        pm.setVisible(true);
        
        this.setVisible(false);
        
      
       
    }//GEN-LAST:event_atrasButtonActionPerformed

    private void eliminarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_eliminarButtonActionPerformed
        
        int fila = this.datosTable.getSelectedRow();
        
        if(fila>=0){
            
            dtm.removeRow(fila);
        }
    }//GEN-LAST:event_eliminarButtonActionPerformed

    private void agregarButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_agregarButtonActionPerformed

       if(!this.indiceTextField.getText().isEmpty() && 
          this.indiceTextField.getText() != null && 
          this.indiceTextField.getText().matches("[0-9]*")==true  &&
          this.costoUnitarioTextField.getText().isEmpty() != true &&
          this.demandaUnidadTextField.getText().isEmpty() != true &&
          this.costoUnitarioTextField.getText() != null && 
          this.demandaUnidadTextField.getText() != null 
          )    
          {
             
              int Dou=0;
          try{
            Double.parseDouble( this.demandaUnidadTextField.getText());
            Double.parseDouble( this.costoUnitarioTextField.getText());
            Dou=1;
          }catch(NumberFormatException nfe)
                  {Dou=0;}
          
          if(Dou==1){
              
        String datos[] = new String[4];
        
        datos[0]=this.indiceTextField.getText();
        
        datos[1]=this.articuloTextField.getText();
           
        datos[2]=this.costoUnitarioTextField.getText();
              
        datos[3]=this.demandaUnidadTextField.getText();
        
        this.indiceTextField.setText(null);
        
        this.articuloTextField.setText(null);
           
        this.costoUnitarioTextField.setText(null);
              
        this.demandaUnidadTextField.setText(null);
        
        dtm.addRow(datos);
        
        this.datosTable.setModel(dtm);
          }
             }
            
    }//GEN-LAST:event_agregarButtonActionPerformed
      
    private void ordenarTable(){
        
         double totalPorcentaje[] = new double[this.datosTable.getRowCount()];
         double indice[] = new double[this.datosTable.getRowCount()];
        
         for(int i=0; i < this.datosTable.getRowCount(); i++){
         
             totalPorcentaje[i]= Double.parseDouble( dtm.getValueAt(i, 5).toString());
             indice[i]= Double.parseDouble( dtm.getValueAt(i, 5).toString());
             
                         
         }
         
      
         
         for(int i =0 ; i<totalPorcentaje.length;i++){
             
             for(int j = i ; j<totalPorcentaje.length;j++){
                 
                if(totalPorcentaje[i] < totalPorcentaje[j]){
                    
                    double aux=totalPorcentaje[i];
                    
                    totalPorcentaje[i]=totalPorcentaje[j];
                    
                    totalPorcentaje[j]=aux;
                                                          
                }
             }
             
         }
                 
         for(int i=0;i< totalPorcentaje.length;i++){
      
             for(int j=0;j< indice.length;j++){
                 
            
             if(totalPorcentaje[i]==indice[j]){
                 
                 String datos[] = new String[6];
        
                 datos[0]=dtm.getValueAt(j, 0).toString();
        
                 datos[1]=dtm.getValueAt(j, 1).toString();
           
                 datos[2]=dtm.getValueAt(j, 2).toString();
              
                 datos[3]=dtm.getValueAt(j, 3).toString();
                 
                 datos[4]=dtm.getValueAt(j, 4).toString();
                 
                 datos[5]=dtm.getValueAt(j, 5).toString();
        
                 dtm.addRow(datos);
        
                 this.datosTable.setModel(dtm);
                 
                 indice[j]=-1;
                 
                
                 
                 
             }
             
             
             }
             
         }
         
       eliminarMitad();
         
         
    }
    
    private void eliminarMitad() {
        int tam=(this.datosTable.getRowCount()/2);
        
        for(int i=0;i<tam;i++){
            
             dtm.removeRow(0);
            
        }
    }
    
    private void acumulado(){
        
        double acumulado=0;
        
        for(int i=0; i<this.datosTable.getRowCount(); i++){
            
            acumulado = acumulado + Double.parseDouble(dtm.getValueAt(i, 5).toString());
            dtm.setValueAt(((double) Math.round( acumulado*100.0) / 100.0), i, 6);
        }
    }
    
    private void abc(){
        
        double num1, num2;
        double aux1,aux2;
        int ind1=0;
        int ind2=0;
        
         num1 = 80 - Double.parseDouble(dtm.getValueAt(0, 6).toString())  ;
            
         num2 = 95 - Double.parseDouble(dtm.getValueAt(0, 6).toString())  ;
         
         if(num1<0)
             num1=num1*-1;
         
          if(num2<0)
             num2=num2*-1;
         
        
        
        for(int i=1; i<this.datosTable.getRowCount(); i++){
           
            aux1=80 - Double.parseDouble(dtm.getValueAt(i, 6).toString()) ;
            aux2=95 - Double.parseDouble(dtm.getValueAt(i, 6).toString()) ;
            
             if(aux1<0)
             aux1=aux1*-1;
         
            if(aux2<0)
             aux2=aux2*-1;
            
           if(num1>aux1){
               
               num1=aux1;
               ind1=i;
           }
           
           if(num2>aux2) {
               
               num2 = aux2;
               ind2=i;
           }
            
           
               
        }
           
       
        
        for(int i=0; i<this.datosTable.getRowCount(); i++){
            
            
            if( Double.parseDouble(dtm.getValueAt(i, 6).toString())  <= Double.parseDouble(dtm.getValueAt(ind1, 6).toString()) ){
                
                 dtm.setValueAt('A', i, 7);
            }
            
             if(Double.parseDouble(dtm.getValueAt(i, 6).toString()) >  Double.parseDouble(dtm.getValueAt(ind1, 6).toString()) && 
                Double.parseDouble(dtm.getValueAt(i, 6).toString()) <= Double.parseDouble(dtm.getValueAt(ind2, 6).toString())){
                
                 dtm.setValueAt('B', i, 7);
            }
             
             if( Double.parseDouble(dtm.getValueAt(i, 6).toString()) > Double.parseDouble(dtm.getValueAt(ind2, 6).toString()) ){
                
                 dtm.setValueAt('C', i, 7);
            }
            
            
          
        }
        
    }
    
    private void abg(){
      
         for(int i=0; i<this.datosTable.getRowCount(); i++){
            
            if( dtm.getValueAt(i, 7).toString().compareTo("A")==0 || Integer.parseInt(dtm.getValueAt(i, 0).toString())==1 ){
                
                 dtm.setValueAt('α', i, 8);
            }else if( dtm.getValueAt(i, 7).toString().compareTo("B")==0 || Integer.parseInt(dtm.getValueAt(i, 0).toString())==2 )
            {
          
                 dtm.setValueAt('β', i, 8);
            }
             else
            {
              if( dtm.getValueAt(i, 7).toString().compareTo("C")==0 || Integer.parseInt(dtm.getValueAt(i, 0).toString())==3 ){
                          
                 dtm.setValueAt('γ', i, 8);
              }
            }
            
            
          
        }
        
    }
    
    private void resultadoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_resultadoButtonActionPerformed
      
       
          
            
        String costo="";
        String demanda="";
        int DemandaAnual=-1;
        int tipoDemanda=this.tipoDemandaComboBox.getSelectedIndex();
        nModeloProgramado nm = new nModeloProgramado();
      
        
        for(int i=0; i < this.datosTable.getRowCount(); i++){
            
            costo =  dtm.getValueAt(i, 2).toString();
            
            demanda = dtm.getValueAt(i, 3).toString();
            
            dtm.setValueAt(nm.calcularDemandaAnualDolares(tipoDemanda, costo, demanda), i, 4); 
            
            nm.calcularTotalDemandaAnual(dtm.getValueAt(i, 4).toString());
                  
        }
        
         
        for(int i=0; i < this.datosTable.getRowCount(); i++){
             
            dtm.setValueAt(nm.calcularPorcentaje(dtm.getValueAt(i, 4).toString()),i,5);
                  
        }
        
        this.ordenarTable();
        
        this.acumulado();
       
        this.abc();
        
        this.abg();
        
      
    }//GEN-LAST:event_resultadoButtonActionPerformed

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        
        
        int tam = this.datosTable.getRowCount();
        for(int i=0; i < tam; i++){
            
             dtm.removeRow(0);
                  
        }
        
        
    }//GEN-LAST:event_jButton1ActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(pModeloABC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(pModeloABC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(pModeloABC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(pModeloABC.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new pModeloABC().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton agregarButton;
    private javax.swing.JTextField articuloTextField;
    private javax.swing.JButton atrasButton;
    private javax.swing.JTextField costoUnitarioTextField;
    private javax.swing.JTable datosTable;
    private javax.swing.JTextField demandaUnidadTextField;
    private javax.swing.JButton eliminarButton;
    private javax.swing.JTextField indiceTextField;
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JToolBar.Separator jSeparator1;
    private javax.swing.JToolBar.Separator jSeparator2;
    private javax.swing.JToolBar.Separator jSeparator3;
    private javax.swing.JToolBar.Separator jSeparator4;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton resultadoButton;
    private javax.swing.JComboBox tipoDemandaComboBox;
    // End of variables declaration//GEN-END:variables
}
